package day8;

import java.util.*;

public class Homework {
    static Map<String,WorldCup> map=new HashMap<>();
    static{  //比较适合做初始化起始数据  最先执行一次
        String[] wins={"乌拉圭","意大利","意大利","乌拉圭","西德","巴西",
                "巴西","英格兰","巴西","西德","阿根廷","意大利","阿根廷",
                "西德","巴西","法国","巴西","意大利","西班牙","德国","法国","阿根廷"};
        String[] addrs={"乌拉圭","意大利","法国","巴西","瑞士","瑞典","智利","英格兰","墨西哥",
                "前西德","阿根廷","西班牙","墨西哥","意大利","美国","法国","日韩",
                "德国","南非","巴西","俄罗斯","卡塔尔"};
        for(int i=0,year=1930;i<addrs.length;i++,year+=4){
            map.put(year+"",new WorldCup(year+"",addrs[i],wins[i]));
            if(year==1938) year+=8;
        }
    }
    public static void main(String[] args) {
        demo2();
    }
    //a.实现斗地主随机发牌的功能 一共54张牌
    //牌的花色分为   梅花   红桃   黑桃  方片
    //牌有  3  4 5 6 7 8 9 10 J  Q K  A  2  大王 小王
    //随机发给两个农民 和一个地主      地主 多三张牌
    //最后显示每人的牌的结果  并且每人的排要根据牌的大小进行降序排列
    public static void demo1(){
        String[] color={"♣","♠","♥","♦"};
        String[] nums={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        List<Card> cards=new ArrayList<>();
        for(String s:color){
            for(int i=0;i<nums.length;i++) {
                cards.add(new Card(s+nums[i],i+3));
            }
        }
        cards.add(new Card("小🃏",16));
        cards.add(new Card("大🃏",17));
        System.out.println(cards);

        Comparator<Card> com=(c1,c2)->{
            int i=c2.num-c1.num;
            if(i==0) i=c1.str.compareTo(c2.str);
            return i;
        };
        Set<Card> squire=new TreeSet<>(com);
        Set<Card> farmer1=new TreeSet<>(com);
        Set<Card> farmer2=new TreeSet<>(com);
        System.out.println("开始洗牌");
        Collections.shuffle(cards);
        while(cards.size()>0) {
            if(cards.size()>3) {
                squire.add(cards.remove(0));
                farmer1.add(cards.remove(0));
                farmer2.add(cards.remove(0));
            }else{
                squire.add(cards.remove(0));
            }
        }
        System.out.println("发牌之后:");
        System.out.println(squire);
        System.out.println(farmer1);
        System.out.println(farmer2);
    }
    //a.利用Map,初始化如下数据，完成下面的功能：
    //从命令行读入一个字符串，表示一个年份，输出该年的世界杯冠军是哪支球队。
    //如果该 年没有举办世界杯，则输出：没有举办世界杯。
    //
    //b.在原有世界杯Map 的基础上，增加如下功能：
    // 读入一支球队的名字，输出该球队夺冠的年份列表
    //例如，读入“巴西”，应当输出 1958 1962 1970 1994 2002
    //读入“荷兰”，应当输出 没有获得过世界杯
    public static void demo2(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入年份");
        String year=sc.next();
        if(map.containsKey(year)){
            WorldCup w=map.get(year);
            System.out.println(year+"年冠军:"+w.win);
        }else{
            System.out.println("没有举办世界杯");
        }
        System.out.println("请输入一个球队");
        String team=sc.next();
        StringBuilder sb=new StringBuilder();
        boolean b=true;
        for(String key:map.keySet()){
            WorldCup w=map.get(key);
            if(w.win.equals(team)){
                sb.append(key+" ");
                b=false;
            }
        }
        if(b) sb.append(team+"没有获得世界杯冠军");

        System.out.println(sb);
    }
}
class Card{
    String str;//存储内容  ♣10
    int num;//存储牌对应的数值
    public Card(String str, int num) {
        this.str = str;
        this.num = num;
    }
    public String toString() {
        return str;
    }
}
class WorldCup{
    String year;
    String addr;
    String win;
    public WorldCup(String year, String addr, String win) {
        this.year = year;
        this.addr = addr;
        this.win = win;
    }
}